import greenfoot.*;

public class GameOverWorld extends World {
    public GameOverWorld(boolean isVictory, int width, int height, int bombs) {    
        super(400, 300, 1);
        Greenfoot.delay(20);
        showMessage(isVictory);
        addObject(new ContinueButton(isVictory, width, height, bombs), 200, 200);
        addObject(new BackButton(), 200, 250); // 返回主菜单
    }

    private void showMessage(boolean isVictory) {
        // 加载自定义背景图像
        GreenfootImage backgroundImage = new GreenfootImage("background1.png"); 
        setBackground(backgroundImage);

        // 创建消息文本
        GreenfootImage messageImage = new GreenfootImage(400, 300);
        messageImage.setColor(new Color(255, 255, 255, 0)); // 半透明背景
        messageImage.fill();
        messageImage.setColor(Color.BLACK);
        
        Font font = new Font("SimSun", false, false, 24);
        messageImage.setFont(font);
        
        if (isVictory) {
            messageImage.drawString("恭喜！你赢了！", 120, 100);
        } else {
            messageImage.drawString("很遗憾，你失败了！", 120, 100);
        }
        
        // 将消息绘制在背景上
        getBackground().drawImage(messageImage, 0, 0);
    }
}
